package com.zj.provider.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.zj.provider.domain.Student;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/provider")
public class StudentController {

    @GetMapping("/find/{name}")
    @HystrixCommand(fallbackMethod = "Get_jiang")//指定降级后的方法
    public Student get(@PathVariable String name){

//        int i=1/0;  //出现错误，会触发降级

            if(name.equals("1")) {
                int i=1/0;
            }
        return new Student(1,name,20);

    }


    //下面是希望降级执行的方法
    public Student Get_jiang(String name){
        System.out.println(name);

        return new Student(2,"降级了",22);
    }
}
